/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "stdafx.h"
#include "计算类JIT函数.h"

#include <omp.h>
#include <matXX.h>
#include <graph采样.h>
#include <core/结构数据.h>
#include <core/动画/curve.h>
#include <core/空间划分/加速结构.h>
#include <core/几何计算/vec_array.h>
#include <core/vec_conversion.h>
#include <basic_common_function.h>


#include <面/面.h>
#include <nmmintrin.h>
#include <immintrin.h>


#define DEF_OMP_FOR DEF_转字符串1(#pragma omp parallel for)

#define DEF_v3_v_加 for (int64 i = 0; i < num; ++i) p_data1[i] = vec_add(v1[i], 是否独立计算 ? v2[i] : v2[0]); break;
#define DEF_v3_v_减 for (int64 i = 0; i < num; ++i) p_data1[i] = vec_sub(v1[i], 是否独立计算 ? v2[i] : v2[0]); break;
#define DEF_v3_v_乘 for (int64 i = 0; i < num; ++i) p_data1[i] = vec_mul(v1[i], 是否独立计算 ? v2[i] : v2[0]); break;
#define DEF_v3_v_除 for (int64 i = 0; i < num; ++i) p_data1[i] = vec_div(v1[i], 是否独立计算 ? v2[i] : v2[0]); break;
#define DEF_v3_v3_叉积 for (int64 i = 0; i < num; ++i) p_data1[i] = vec_cross(v1[i], 是否独立计算 ? v2[i] : v2[0]); break;
//#define DEF_v3s_v3s_叉积 for (int64 i = 0; i < num; ++i) p_data1[i] = vec_cross(v1[i], 是否独立计算 ? v2[i] : v2[i]); break;



vec3 f_JIT_Fun_vec3_c_f32(DEF_V3_F_参数) {
	switch (计算方式) {
	case 0: return vec_add(data1, data2);
	case 1: return vec_sub(data1, data2);
	case 2: return vec_mul(data1, data2);
	case 3: return vec_div(data1, data2);
	}
	return {};
}

vec3 f_JIT_Fun_vec3_c_vec3(DEF_V3_V3_参数) {
	switch (计算方式) {
	case 0: return vec_add(data1, data2);
	case 1: return vec_sub(data1, data2);
	case 2: return vec_mul(data1, data2);
	case 3: return vec_div(data1, data2);
	case 4: return vec_cross(data1, data2);
	case 5: return vec_cross(data1, data2);
	}
	return {};
}

template<typename T1, typename T2, typename T3>
void f_单值数组计算(T1* a, T2* b, T3* r, uint32 num, uint8 方式) {
	S_UI32Array* a_index = f_core_array_Index((S_Array*)a);
	S_UI32Array* b_index = f_core_array_Index((S_Array*)b);

	uint32 v1Num;
	uint32 v2Num;
	uint32* 索引1 = f_array_多例索引((S_Array*)a, v1Num);
	uint32* 索引2 = f_array_多例索引((S_Array*)b, v2Num);

	if (索引1 || 索引2) {
		num = DEF_Max(v1Num, v2Num);

		f_core_array_resize((S_Array*)r, num);
		bool 源a多例 = v1Num >= num;
		bool 源b多例 = v2Num >= num;

		for (int32 i = 0; i < num; ++i) {
			uint32 i1;
			if (索引1) {
				i1 = 源a多例 ? 索引1[i] : 索引1[0];
			}
			else {
				i1 = 源a多例 ? i : 0;
			}
			uint32 i2;
			if (索引2) {
				i2 = 源b多例 ? 索引2[i] : 索引2[0];
			}
			else {
				i2 = 源b多例 ? i : 0;
			}

			switch (方式) {
				case 0: r->ptr_userData[i] = a->ptr_userData[i1] + b->ptr_userData[i2]; break;
				case 1: r->ptr_userData[i] = a->ptr_userData[i1] - b->ptr_userData[i2]; break;
				case 2: r->ptr_userData[i] = a->ptr_userData[i1] * b->ptr_userData[i2]; break;
				case 3: r->ptr_userData[i] = a->ptr_userData[i1] / b->ptr_userData[i2]; break;

				case 4: r->ptr_userData[i] = DEF_Max(a->ptr_userData[i1], b->ptr_userData[i2]); break;
				case 5: r->ptr_userData[i] = DEF_Min(a->ptr_userData[i1], b->ptr_userData[i2]); break;
				case 6: r->ptr_userData[i] = int32(a->ptr_userData[i1]) % int32(DEF_Max(b->ptr_userData[i2],1)); break;
			}
		}
	}
	else {
		bool in1多例 = a->count >= num;
		bool in2多例 = b->count >= num;
		f_core_array_resize((S_Array*)r, num);


		for (int32 i = 0; i < num; ++i) {
			auto p0 = in1多例 ? a->ptr_userData[i] : a->ptr_userData[0];
			auto p1 = in2多例 ? b->ptr_userData[i] : b->ptr_userData[0];

			switch (方式) {
				case 0: r->ptr_userData[i] = p0 + p1; break;
				case 1: r->ptr_userData[i] = p0 - p1; break;
				case 2: r->ptr_userData[i] = p0 * p1; break;
				case 3: r->ptr_userData[i] = p0 / p1; break;

				case 4: r->ptr_userData[i] = DEF_Max(p0, p1); break;
				case 5: r->ptr_userData[i] = DEF_Min(p0, p1); break;
				case 6: r->ptr_userData[i] = int32(p0) % int32(DEF_Max(p1,1)); break;
			}
		}
	}
}


void f_JIT_Fn_三角函数s(S_F32Array* inData, S_F32Array* outData, uint8 type) {
	uint32 num = inData->count;
	f_core_array_resize((S_Array*)outData, num);

	float32* inptr = inData->ptr_userData;
	float32* outptr = outData->ptr_userData;

	for (uint32 i = 0; i < num; ++i) {
		switch (type) {
		case 0: outptr[i] = sinf(inptr[i]); break;
		case 1: outptr[i] = cosf(inptr[i]); break;
		case 2: outptr[i] = tanf(inptr[i]); break;

		case 3: outptr[i] = asinf(inptr[i]); break;
		case 4: outptr[i] = acosf(inptr[i]); break;
		case 5: outptr[i] = atanf(inptr[i]); break;

		case 6: outptr[i] = sinhf(inptr[i]); break;
		case 7: outptr[i] = coshf(inptr[i]); break;
		case 8: outptr[i] = tanhf(inptr[i]); break;

		case 9: outptr[i] = asinhf(inptr[i]); break;
		case 10: outptr[i] = acoshf(inptr[i]); break;
		case 11: outptr[i] = atanhf(inptr[i]); break;
		default:
			break;
		}
	}
}

float32 f_JIT_Fn_三角函数(float32 inData, uint8 type) {
	switch (type) {
	case 0: return sinf(inData); 
	case 1: return cosf(inData); 
	case 2: return tanf(inData); 
			
	case 3: return asinf(inData); 
	case 4: return acosf(inData); 
	case 5: return atanf(inData); 
			
	case 6: return sinhf(inData); 
	case 7: return coshf(inData); 
	case 8: return tanhf(inData); 
			
	case 9: return asinhf(inData);
	case 10:return acoshf(inData);
	case 11:return atanhf(inData);
	default:
		break;
	}
	return 0;
}

void f_JIT_Fn_向量归一化s(S_Vec3Array* inData, S_Vec3Array* outData) {
	uint32 num = inData->count;
	f_core_array_resize((S_Array*)outData, num);

	vec3* inptr = inData->ptr_userData;
	vec3* outptr = outData->ptr_userData;

	for (uint32 i = 0; i < num; ++i) {
		outptr[i] = vec_normalize(inptr[i]);
	}
}

void f_JIT_Fn_逻辑计算m(S_F32Array* inDataA, S_F32Array* inDataB, S_I8Array* outData, uint8 方式) {
	uint32 num = DEF_Max(inDataA->count, inDataB->count);

	bool 独立A = inDataA->count >= num;
	bool 独立B = inDataB->count >= num;

	f_core_array_resize((S_Array*)outData, num);

	float32* ap = inDataA->ptr_userData;
	float32* bp = inDataB->ptr_userData;
	int8* rp = outData->ptr_userData;

//#pragma omp parallel for
	for (int32 i = 0; i < num; ++i) {
		switch (方式) {
			case 0: rp[i] = (独立A ? ap[i] : ap[0]) > (独立B ? bp[i] : bp[0]); break;
			case 1: rp[i] = (独立A ? ap[i] : ap[0]) < (独立B ? bp[i] : bp[0]); break;
			case 2: rp[i] = (独立A ? ap[i] : ap[0]) >= (独立B ? bp[i] : bp[0]); break;
			case 3: rp[i] = (独立A ? ap[i] : ap[0]) <= (独立B ? bp[i] : bp[0]); break;
			case 4: rp[i] = (独立A ? ap[i] : ap[0]) == (独立B ? bp[i] : bp[0]); break;
			case 5: rp[i] = (独立A ? ap[i] : ap[0]) != (独立B ? bp[i] : bp[0]); break;
			case 6: rp[i] = (独立A ? ap[i] : ap[0]) && (独立B ? bp[i] : bp[0]); break;
			case 7: rp[i] = (独立A ? ap[i] : ap[0]) || (独立B ? bp[i] : bp[0]); break;
		}
	}
}

void f_JIT_Fn_逻辑计算(float32 inDataA, float32 inDataB, int8& outData, uint8 方式) {
	switch (方式) {
		case 0: outData = inDataA >  inDataB; break;
		case 1: outData = inDataA <  inDataB; break;
		case 2: outData = inDataA >= inDataB; break;
		case 3: outData = inDataA <= inDataB; break;
		case 4: outData = inDataA == inDataB; break;
		case 5: outData = inDataA != inDataB; break;
		case 6: outData = inDataA && inDataB; break;
		case 7: outData = inDataA || inDataB; break;
	}
}

void f_JIT_Fn_单目计算m(S_F32Array* inDataA, S_F32Array* outData, int32 方式) {
	f_core_array_resize((S_Array*)outData, inDataA->count);

	for (uint32 i = 0; i < inDataA->count; ++i) {
		switch (方式) {
			case 0: outData->ptr_userData[i] = sign(inDataA->ptr_userData[i]); break;
			case 1: outData->ptr_userData[i] = !(inDataA->ptr_userData[i]); break;
			case 2: outData->ptr_userData[i] = (inDataA->ptr_userData[i]) + 1; break;
			case 3: outData->ptr_userData[i] = (inDataA->ptr_userData[i]) - 1; break;
			case 4: outData->ptr_userData[i] = (inDataA->ptr_userData[i]) ? 1 : - 1; break;
		}
	}
}


void f_JIT_Fn_矢量逻辑计算m(S_Vec3Array* inDataA, S_Vec3Array* inDataB, S_I8Array* outData, uint8 方式) {
	uint32 num = DEF_Max(inDataA->count, inDataB->count);

	bool 独立A = inDataA->count >= num;
	bool 独立B = inDataB->count >= num;

	f_core_array_resize((S_Array*)outData, num);

	vec3* ap = inDataA->ptr_userData;
	vec3* bp = inDataB->ptr_userData;
	int8* rp = outData->ptr_userData;

	//for (uint32 i = 0; i < num; ++i) {
	//	switch (方式) {
	//		case 0: rp[i] = 独立A ? ap[i] : ap[0] > 独立B ? bp[i] : bp[0]; break;
	//		case 1: rp[i] = 独立A ? ap[i] : ap[0] < 独立B ? bp[i] : bp[0]; break;
	//		case 2: rp[i] = 独立A ? ap[i] : ap[0] >= 独立B ? bp[i] : bp[0]; break;
	//		case 3: rp[i] = 独立A ? ap[i] : ap[0] <= 独立B ? bp[i] : bp[0]; break;
	//		case 4: rp[i] = 独立A ? ap[i] : ap[0] == 独立B ? bp[i] : bp[0]; break;
	//		case 5: rp[i] = 独立A ? ap[i] : ap[0] != 独立B ? bp[i] : bp[0]; break;
	//		case 6: rp[i] = 独立A ? ap[i] : ap[0] && 独立B ? bp[i] : bp[0]; break;
	//		case 7: rp[i] = 独立A ? ap[i] : ap[0] || 独立B ? bp[i] : bp[0]; break;
	//	}
	//}
}
void f_JIT_Fn_矢量逻辑计算(const vec3& inDataA, const vec3& inDataB, int8& outData, uint8 方式) {
	//switch (方式) {
	//	case 0: outData = inDataA > inDataB; break;
	//	case 1: outData = inDataA < inDataB; break;
	//	case 2: outData = inDataA >= inDataB; break;
	//	case 3: outData = inDataA <= inDataB; break;
	//	case 4: outData = inDataA == inDataB; break;
	//	case 5: outData = inDataA != inDataB; break;
	//	case 6: outData = inDataA && inDataB; break;
	//	case 7: outData = inDataA || inDataB; break;
	//}
}




vec3 f_JIT_Fn_设置矢量分量(const vec3& 矢量, float32 分量, int8 分量ID) {
	vec3 新矢量 = 矢量;
	((float32*)&新矢量)[DEF_Min(DEF_Max(分量ID, 0), 2)] = 分量;

	分量ID = clamp(分量ID, 0, 2);
	switch (分量ID) {
		case 0: 新矢量.x = 分量; break;
		case 1: 新矢量.y = 分量; break;
		case 2: 新矢量.z = 分量; break;
	}

	return 新矢量;
}

void f_JIT_Fn_设置矢量分量m(const S_Vec3Array* 矢量, const S_F32Array* 分量, int8 分量ID, S_Vec3Array* 返回矢量) {
	uint32 num = DEF_Max(矢量->count, 分量->count);

	bool 源矢量多例 = 矢量->count >= num;
	bool 源分量多例 = 分量->count >= num;

	uint32 v1Num;
	uint32* 索引1 = f_array_多例索引((S_Array*)矢量, v1Num);
	uint32 v2Num;
	uint32* 索引2 = f_array_多例索引((S_Array*)分量, v2Num);


	if (索引1 || 索引2) {
		//num = DEF_Max(索引1 ? v1Num : num, 索引2 ? v2Num : num);
		if (索引1) {
			num = v1Num;
		}
		else if (索引2) {
			num = v2Num;
		}

		f_core_array_resize((S_Array*)返回矢量, num);
		分量ID = clamp(分量ID, 0, 2);

		源矢量多例 = v1Num >= num;
		源分量多例 = v2Num >= num;

		for (uint32 i = 0; i < num; ++i) {
			vec3 v;
			if (索引1) {
				v = 源矢量多例 ? 矢量->ptr_userData[索引1[i]] : 矢量->ptr_userData[索引1[0]];
			}
			else {
				v = 源矢量多例 ? 矢量->ptr_userData[i] : 矢量->ptr_userData[0];
			}

			if (索引2) {
				((float32*)&v)[分量ID] = 源分量多例 ? 分量->ptr_userData[索引2[i]] : 分量->ptr_userData[索引2[0]];
			}
			else {
				((float32*)&v)[分量ID] = 源分量多例 ? 分量->ptr_userData[i] : 分量->ptr_userData[0];
			}
			
			返回矢量->ptr_userData[i] = v;
		}
	}
	else {
		f_core_array_resize((S_Array*)返回矢量, num);
		分量ID = clamp(分量ID, 0, 2);

		for (uint32 i = 0; i < num; ++i) {
			vec3 v = 源矢量多例 ? 矢量->ptr_userData[i] : 矢量->ptr_userData[0];

			switch (分量ID) {
				case 0: v.x = 源分量多例 ? 分量->ptr_userData[i] : 分量->ptr_userData[0]; break;
				case 1: v.y = 源分量多例 ? 分量->ptr_userData[i] : 分量->ptr_userData[0]; break;
				case 2: v.z = 源分量多例 ? 分量->ptr_userData[i] : 分量->ptr_userData[0]; break;
			}
			返回矢量->ptr_userData[i] = v;
		}
	}
}

void f_JIT_Fn_混合m(const S_F32Array* a, const S_F32Array* b, const S_F32Array* c, S_F32Array* 返回矢量) {
	uint32 num = DEF_Max(a->count, b->count);
	num = DEF_Max(num, c->count);

	f_core_array_resize((S_Array*)返回矢量, num);

	bool a独立 = a->count >= num;
	bool b独立 = b->count >= num;
	bool c独立 = c->count >= num;

	for (uint32 i = 0; i < num; ++i) {
		返回矢量->ptr_userData[i] = mix(
			a独立 ? a->ptr_userData[i] : a->ptr_userData[0],
			b独立 ? b->ptr_userData[i] : b->ptr_userData[0],
			clamp(c独立 ? c->ptr_userData[i] : c->ptr_userData[0], 0, 1)
		);
	}
}

void f_JIT_Fn_矢量混合m(const S_Vec3Array* a, const S_Vec3Array* b, const S_F32Array* c, S_Vec3Array* 返回矢量) {
	uint32 num = DEF_Max(a->count, b->count);
	num = DEF_Max(num, c->count);

	
	uint32 v1Num;
	uint32 v2Num;
	uint32 v3Num;
	uint32* 索引1 = f_array_多例索引((S_Array*)a, v1Num);
	uint32* 索引2 = f_array_多例索引((S_Array*)b, v2Num);
	uint32* 索引3 = f_array_多例索引((S_Array*)c, v3Num);

	if (索引1 || 索引2 || 索引3) {
		num = DEF_Max(v1Num, v2Num);
		num = DEF_Max(v3Num, num);
		
		f_core_array_resize((S_Array*)返回矢量, num);
		bool 源a多例 = v1Num >= num;
		bool 源b多例 = v2Num >= num;
		bool 源c多例 = v3Num >= num;


		for (uint32 i = 0; i < num; ++i) {
			uint32 i1;
			if (索引1) {
				i1 = 源a多例 ? 索引1[i] : 索引1[0];
				if(i1 >= a->count) i1 = 0;
			}
			else {
				i1 = 源a多例 ? i : 0;
			}
			uint32 i2;
			if (索引2) {
				i2 = 源b多例 ? 索引2[i] : 索引2[0];
				if (i2 >= a->count) i2 = 0;
			}
			else {
				i2 = 源b多例 ? i : 0;
			}
			uint32 i3;
			if (索引3) {
				i3 = 源c多例 ? 索引3[i] : 索引3[0];
				if (i3 >= a->count) i3 = 0;
			}
			else {
				i3 = 源c多例 ? i : 0;
			}

			返回矢量->ptr_userData[i] = mix(a->ptr_userData[i1], b->ptr_userData[i2],clamp(c->ptr_userData[i3], 0, 1));
		}
	}
	else {
		f_core_array_resize((S_Array*)返回矢量, num);

		bool a独立 = a->count >= num;
		bool b独立 = b->count >= num;
		bool c独立 = c->count >= num;

		for (uint32 i = 0; i < num; ++i) {
			返回矢量->ptr_userData[i] = mix(
				a独立 ? a->ptr_userData[i] : a->ptr_userData[0],
				b独立 ? b->ptr_userData[i] : b->ptr_userData[0],
				clamp(c独立 ? c->ptr_userData[i] : c->ptr_userData[0], 0, 1)
			);
		}
	}
}

#define DEF_V3S_Fs_参数 const S_Vec3Array* data1, const S_F32Array* data2, S_Vec3Array* r, uint8 计算方式
static void f_JIT_Fun_vec3s_c_fs(DEF_V3S_Fs_参数) {
	vec3* v1 = data1->ptr_userData;
	float32* v2 = data2->ptr_userData;

	uint32 num = data1->count;
	uint32 num2 = data2->count;

	f_core_array_resize((S_Array*)r, num);
	((std::vector<vec3>*)r)->resize(num);
	vec3* p_data1 = r->ptr_userData;


	bool 是否独立计算 = false;
	if (num2 >= num) {
		是否独立计算 = true;
	}

	switch (计算方式) {
	case 0: {
#pragma omp parallel for num_threads(DEF_Min(2, num+1))
		DEF_v3_v_加
	}
	case 1: {
#pragma omp parallel for num_threads(DEF_Min(2, num+1))
		DEF_v3_v_减
	}
	case 2: {
#pragma omp parallel for num_threads(DEF_Min(2, num+1))
		DEF_v3_v_乘
	}
	case 3: {
#pragma omp parallel for num_threads(DEF_Min(2, num+1))
		DEF_v3_v_除
	}
	case 4: {
		std::cout << "vec3 该选项不能计算" << std::endl;
		break;
	}
	case 5: {
		break;
	}
	case 6: {

		break;
	}
	case 7: {
		break;
	}
	}

}


//#define DEF_V3s_V3s_参数 const S_Vec3Array* data1, const S_Vec3Array* data2, S_Vec3Array* r, uint8 计算方式
S_Vec3Array* f_JIT_Fun_vec3s_c_vec3s(const S_Vec3Array* data1, const S_Vec3Array* data2, S_Vec3Array* r, int32 方式) {
	uint32 num = DEF_Max(data1->count, data2->count);
	ivec3 dim;
	
	vec3* v1 = data1->ptr_userData;
	vec3* v2 = data2->ptr_userData;

	S_UI32Array* v1Index = f_core_array_Index((S_Array*)data1);
	S_UI32Array* v2Index = f_core_array_Index((S_Array*)data2);

	//f_omp_set_threadsNum(DEF_Min(16, num));


	uint32 v1Num;
	uint32 v2Num;
	

	typedef vec3(*vec_计算)(const vec3& vec, const vec3& value);
	vec_计算 fun;

	switch (方式) {
		case 0: fun = vec_add; break;
		case 1: fun = vec_sub; break;
		case 2: fun = vec_mul; break;
		case 3: fun = vec_div; break;
		case 4: fun = vec_cross; break;
		case 5: {
			f_core_array_resize((S_Array*)r, data1->count * data2->count);

			for (uint32 i = 0; i < data2->count; ++i) {
				uint32 index = i * data1->count;
				for (uint32 k = 0; k < data1->count; ++k) {
					r->ptr_userData[index + k] = data1->ptr_userData[k] + data2->ptr_userData[i];
				}
			}
			return r;
		}
	}

	
	if (v1Index || v2Index) {
		if (data1->count >= data2->count) {
			f_core_array_copy((S_Array*)r, (S_Array*)data1);
			dim = f_core_array_getDim((S_Array*)data1);
		}
		else {
			f_core_array_copy((S_Array*)r, (S_Array*)data2);
			dim = f_core_array_getDim((S_Array*)data2);
		}
		
		uint32* 索引1 = f_array_多例索引((S_Array*)data1, v1Num);
		uint32* 索引2 = f_array_多例索引((S_Array*)data2, v2Num);


		num = DEF_Max(v1Num, v2Num);
		bool 索引1多例 = v1Num >= num;
		bool 索引2多例 = v2Num >= num;

		f_core_array_resize((S_Array*)r, num);
		vec3* p_outData = r->ptr_userData;


//#pragma omp parallel for
		for (int64 i = 0; i < num; ++i) {
			uint32 i1;
			if (索引1) {
				i1 = 索引1多例 ? 索引1[i] : 索引1[0];
			}
			else {
				i1 = 索引1多例 ? i : 0;
			}
			uint32 i2;
			if (索引2) {
				i2 = 索引2多例 ? 索引2[i] : 索引2[0];
			}
			else {
				i2 = 索引2多例 ? i : 0;
			}
			//p_outData[索引1 ? i1 : i2] = fun(v1[i1], v2[i2]);
			p_outData[i] = fun(v1[i1], v2[i2]);
		}
	}
	else {
		if (data1->count >= data2->count) {
			dim = f_core_array_getDim((S_Array*)data1);
		}
		else {
			dim = f_core_array_getDim((S_Array*)data2);
		}

		f_core_array_resize((S_Array*)r, num);
		vec3* p_outData = r->ptr_userData;

		bool 插座1单例 = data1->count < num;
		bool 插座2单例 = data2->count < num;


		if (num > 100000000) {
#pragma omp parallel for num_threads(DEF_Min(2, num+1))
			for (int64 i = 0; i < num; ++i) {
				p_outData[i] = fun(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
			}
		}
		else {
			for (int64 i = 0; i < num; ++i) {
				p_outData[i] = fun(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
			}
		}
	}

	
	f_core_array_setDim((S_Array*)r, dim);
	return r;
}

//static void f_JIT_Fun_vec3s_c_vec3s(const S_iVec3Array* data1, const S_iVec3Array* data2, S_iVec3Array* r, uint8 计算方式) {
//	ivec3* v1 = data1->ptr_userData;
//	ivec3* v2 = data2->ptr_userData;
//
//	uint32 num = DEF_Max(data1->count, data2->count);
//
//	f_core_array_resize((S_Array*)r, num);
//	ivec3* p_outData = r->ptr_userData;
//
//
//	bool 插座1单例 = data1->count < num;
//	bool 插座2单例 = data2->count < num;
//
//	if (num > 100000000) {
//		switch (计算方式) {
//			case 0: {
//			#pragma omp parallel for
//				for (int64 i = 0; i < num; ++i) {
//					p_outData[i] = vec_add(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
//				}
//			}
//			case 1: {
//			#pragma omp parallel for
//				for (int64 i = 0; i < num; ++i) {
//					p_outData[i] = vec_sub(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
//				}
//			}
//			case 2: {
//			#pragma omp parallel for
//				for (int64 i = 0; i < num; ++i) {
//					p_outData[i] = vec_mul(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
//				}
//			}
//			case 3: {
//			#pragma omp parallel for
//				for (int64 i = 0; i < num; ++i) {
//					p_outData[i] = vec_div(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
//				}
//			}
//			case 4: {
//			#pragma omp parallel for
//				for (int64 i = 0; i < num; ++i) {
//					p_outData[i] = vec_cross(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
//				}
//				break;
//			}
//		}
//	}
//	else {
//		switch (计算方式) {
//			case 0: {
//				for (int64 i = 0; i < num; ++i) {
//					p_outData[i] = vec_add(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
//				}
//				break;
//			}
//			case 1: {
//				for (int64 i = 0; i < num; ++i) {
//					p_outData[i] = vec_sub(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
//				}
//				break;
//			}
//			case 2: {
//				for (int64 i = 0; i < num; ++i) {
//					p_outData[i] = vec_mul(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
//				}
//				break;
//			}
//			case 3: {
//				for (int64 i = 0; i < num; ++i) {
//					p_outData[i] = vec_div(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
//				}
//				break;
//			}
//			case 4: {
//				for (int64 i = 0; i < num; ++i) {
//					p_outData[i] = vec_cross(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
//				}
//				break;
//			}
//		}
//	}
//}

void f_JIT_Fun_两向量计算向量(const S_Vec3Array* data1, const S_Vec3Array* data2, const S_UI32Array* index, S_Vec3Array* r, uint8 计算方式) {
	vec3* v1 = data1->ptr_userData;
	vec3* v2 = data2->ptr_userData;

	uint32 num = DEF_Max(data1->count, data2->count);

	f_core_array_resize((S_Array*)r, num);
	vec3* p_outData = r->ptr_userData;


	bool 插座1单例 = data1->count < num;
	bool 插座2单例 = data2->count < num;

	if (num > 100000000) {
		switch (计算方式) {
			case 0: {
			#pragma omp parallel for num_threads(DEF_Min(2, num))
				for (int64 i = 0; i < num; ++i) {
					p_outData[i] = vec_add(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
				}
			}
			case 1: {
			#pragma omp parallel for num_threads(DEF_Min(2, num))
				for (int64 i = 0; i < num; ++i) {
					p_outData[i] = vec_sub(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
				}
			}
			case 2: {
			#pragma omp parallel for num_threads(DEF_Min(2, num))
				for (int64 i = 0; i < num; ++i) {
					p_outData[i] = vec_mul(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
				}
			}
			case 3: {
			#pragma omp parallel for num_threads(DEF_Min(2, num))
				for (int64 i = 0; i < num; ++i) {
					p_outData[i] = vec_div(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
				}
			}
			case 4: {
			#pragma omp parallel for num_threads(DEF_Min(2, num))
				for (int64 i = 0; i < num; ++i) {
					p_outData[i] = vec_cross(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
				}
				break;
			}
		}
	}
	else {
		switch (计算方式) {
			case 0: {
				for (int64 i = 0; i < num; ++i) {
					p_outData[i] = vec_add(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
				}
				break;
			}
			case 1: {
				for (int64 i = 0; i < num; ++i) {
					p_outData[i] = vec_sub(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
				}
				break;
			}
			case 2: {
				for (int64 i = 0; i < num; ++i) {
					p_outData[i] = vec_mul(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
				}
				break;
			}
			case 3: {
				for (int64 i = 0; i < num; ++i) {
					p_outData[i] = vec_div(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
				}
				break;
			}
			case 4: {
				for (int64 i = 0; i < num; ++i) {
					p_outData[i] = vec_cross(插座1单例 ? v1[0] : v1[i], 插座2单例 ? v2[0] : v2[i]);
				}
				break;
			}
		}
	}
}



#define DEF_V3S_F_参数 const S_Vec3Array* data1, float32 v2, S_Vec3Array* r, uint8 计算方式
static void f_JIT_Fun_vec3s_c_f(DEF_V3S_F_参数) {
	vec3* v1 = data1->ptr_userData;

	uint32 num = data1->count;
	f_core_array_resize((S_Array*)r, num);
	
	vec3* p_data1 = data1->ptr_userData;

	if (num > 100000000) {
		switch (计算方式) {
			case 0: {
			#pragma omp parallel for num_threads(DEF_Min(2, num))
				for (int64 i = 0; i < num; ++i) p_data1[i] = vec_add(v1[i], v2);
				break;
			}
			case 1: {
			#pragma omp parallel for num_threads(DEF_Min(2, num))
				for (int64 i = 0; i < num; ++i) p_data1[i] = vec_sub(v1[i], v2);
				break;
			}
			case 2: {
			#pragma omp parallel for num_threads(DEF_Min(2, num))
				for (int64 i = 0; i < num; ++i) p_data1[i] = vec_mul(v1[i], v2);
				break;
			}
			case 3: {
			#pragma omp parallel for num_threads(DEF_Min(2, num))
				for (int64 i = 0; i < num; ++i) p_data1[i] = vec_div(v1[i], v2);
				break;
			}
			case 4: {
				break;
			}
			case 5: {
				break;
			}
			case 6: {

				break;
			}
			case 7: {
				break;
			}
		}
	}
	else {
		switch (计算方式) {
			case 0: {
				for (int64 i = 0; i < num; ++i) p_data1[i] = vec_add(v1[i], v2);
				break;
			}
			case 1: {
				for (int64 i = 0; i < num; ++i) p_data1[i] = vec_sub(v1[i], v2);
				break;
			}
			case 2: {
				for (int64 i = 0; i < num; ++i) p_data1[i] = vec_mul(v1[i], v2);
				break;
			}
			case 3: {
				for (int64 i = 0; i < num; ++i) p_data1[i] = vec_div(v1[i], v2);
				break;
			}
			case 4: {
				break;
			}
			case 5: {
				break;
			}
			case 6: {

				break;
			}
			case 7: {
				break;
			}
		}
	}


}




#define DEF_Fs_F_F_参数 void* 参数0, float32 参数1, float32 参数2
static void* f_JIT_Fun_合并XYZ_fsff(DEF_Fs_F_F_参数) {
	float32* v0 = ((std::vector<float32>*)参数0)->data();
	uint32 num = ((std::vector<float32>*)参数0)->size();

	auto* r = new std::vector<vec3>(num);
	vec3* r_ptr = r->data();

//#pragma omp parallel for
	for (int32 i = 0; i < num; ++i) {
		r_ptr[i] = { v0[i], 参数1, 参数2 };
	}
	return r;
}

#define DEF_Fs_Fs_F_参数 void* 参数0, void* 参数1, float32 参数2
static void* f_JIT_Fun_合并XYZ_fsfsf(DEF_Fs_Fs_F_参数) {
	float32* v0 = ((std::vector<float32>*)参数0)->data();
	float32* v1 = ((std::vector<float32>*)参数1)->data();

	uint32 num = ((std::vector<float32>*)v0)->size();

	auto* r = new std::vector<vec3>(num);
	vec3* r_ptr = r->data();

//#pragma omp parallel for
	for (int32 i = 0; i < num; ++i) {
		r_ptr[i] = { v0[i], v1[i], 参数2 };
	}
	return r;
}

#define DEF_Fs_F_Fs_参数 void* 参数0, float32 参数1, void* 参数2
static void* f_JIT_Fun_合并XYZ_fsfsfs(DEF_Fs_F_Fs_参数) {
	float32* v0 = ((std::vector<float32>*)参数0)->data();
	float32* v2 = ((std::vector<float32>*)参数2)->data();

	uint32 num = ((std::vector<float32>*)v0)->size();

	auto* r = new std::vector<vec3>(num);
	vec3* r_ptr = r->data();

//#pragma omp parallel for
	for (int32 i = 0; i < num; ++i) {
		r_ptr[i] = { v0[i], 参数1, v2[i] };
	}
	return r;
}

#define DEF_Fs_Fs_Fs_参数 void* 参数0, void* 参数1, void* 参数2
static void* f_JIT_Fun_合并XYZ_fsfsfs(DEF_Fs_Fs_Fs_参数) {
	float32* v0 = ((std::vector<float32>*)参数0)->data();
	float32* v1 = ((std::vector<float32>*)参数1)->data();
	float32* v2 = ((std::vector<float32>*)参数2)->data();

	uint32 num = ((std::vector<float32>*)v0)->size();

	auto* r = new std::vector<vec3>(num);
	vec3* r_ptr = r->data();
	for (uint32 i = 0; i < num; ++i) {
		r_ptr[i] = { v0[i], v1[i], v2[i] };
	}
	return r;
}






#define DEF_构建矩阵_m_m_参数 const Mat44f& mat1, const Mat44f& mat2, uint8 m_计算方式
static Mat44f f_JIT_Fun_矩阵计算_mm(DEF_构建矩阵_m_m_参数) {
	Mat44f outMat;
	switch (m_计算方式) {
	case 0: {
		outMat = mat1 * mat2;
		break;
	}
	case 1: {
		//outMat = f_mat44_Inverse(mat1);
		outMat = f_mat44_Invert(mat1);
		break;
	}
	case 2: {
		outMat = mat1;
		mat44_normalize(outMat);
		break;
	}
	}
	return outMat;
}

#define DEF_构建矩阵_m_ms_参数 const Mat44f& mat1, const void* mat2, uint8 m_计算方式
static void* f_JIT_Fun_矩阵计算_mms(DEF_构建矩阵_m_ms_参数) {
	Mat44f* m2 = (*(std::vector<Mat44f>*)mat2).data();
	uint32 num = (*(std::vector<Mat44f>*)mat2).size();

	auto r = new std::vector<Mat44f>(num);
	if (!num) return r;

	Mat44f* mat_ptr = r->data();
	bool in2单例 = (*(std::vector<Mat44f>*)mat2).size() < num;

	switch (m_计算方式) {
	case 0: {
		for (uint32 i = 0; i < num; ++i) {
			Mat44f* inMat_b;
			if (in2单例) inMat_b = &m2[0];
			else inMat_b = &m2[i];
			mat_ptr[i] = mat1 * (*inMat_b);
		}
		break;
	}
	case 1: {
		for (uint32 i = 0; i < num; ++i) {
			//mat_ptr[i] = f_mat44_Inverse(mat1);
			mat_ptr[i] = f_mat44_Invert(mat1);
		}
		break;
	}
	case 2: {
		for (uint32 i = 0; i < num; ++i) {
			mat_ptr[i] = mat1;
			mat44_normalize(mat_ptr[i]);
		}
		break;
	}
	}
	return r;
}

#define DEF_构建矩阵_ms_m_参数 const void* mat1, const Mat44f& mat2, uint8 m_计算方式
static void* f_JIT_Fun_矩阵计算_msm(DEF_构建矩阵_ms_m_参数) {
	Mat44f* m1 = (*(std::vector<Mat44f>*)mat1).data();
	uint32 num = (*(std::vector<Mat44f>*)mat1).size();

	auto r = new std::vector<Mat44f>(num);
	if (!num) return r;

	Mat44f* mat_ptr = r->data();

	bool in1单例 = (*(std::vector<Mat44f>*)mat1).size() < num;

	switch (m_计算方式) {
	case 0: {
		for (uint32 i = 0; i < num; ++i) {
			Mat44f* inMat_a;
			if (in1单例) inMat_a = &m1[0];
			else inMat_a = &m1[i];
			mat_ptr[i] = (*inMat_a) * (mat2);
		}
		break;
	}
	case 1: {
		for (uint32 i = 0; i < num; ++i) {
			//mat_ptr[i] = f_mat44_Inverse(m1[i]);
			mat_ptr[i] = f_mat44_Invert(m1[i]);
		}
		break;
	}
	case 2: {
		for (uint32 i = 0; i < num; ++i) {
			mat_ptr[i] = m1[i];
			mat44_normalize(mat_ptr[i]);
		}
		break;
	}
	}
	return r;
}

#define DEF_构建矩阵_ms_ms_参数 const void* mat1, const void* mat2, uint8 m_计算方式
static void* f_JIT_Fun_矩阵计算_msms(DEF_构建矩阵_ms_ms_参数) {
	Mat44f* m1 = (*(std::vector<Mat44f>*)mat1).data();
	Mat44f* m2 = (*(std::vector<Mat44f>*)mat2).data();

	uint32 num = (*(std::vector<Mat44f>*)mat1).size();
	uint32 num2 = (*(std::vector<Mat44f>*)mat2).size();

	num = DEF_Max(num, num2);

	auto r = new std::vector<Mat44f>(num);
	if (!num) return r;

	Mat44f* mat_ptr = r->data();

	bool in1单例 = (*(std::vector<Mat44f>*)mat1).size() < num;
	bool in2单例 = (*(std::vector<Mat44f>*)mat2).size() < num;

	switch (m_计算方式) {
	case 0: {
		for (uint32 i = 0; i < num; ++i) {
			Mat44f* inMat_a;
			Mat44f* inMat_b;

			if (in1单例) inMat_a = &m1[0];
			else inMat_a = &m1[i];

			if (in2单例) inMat_b = &m2[0];
			else inMat_b = &m2[i];

			mat_ptr[i] = (*inMat_a) * (*inMat_b);
		}
		break;
	}
	case 1: {
		for (uint32 i = 0; i < num; ++i) {
			//mat_ptr[i] = f_mat44_Inverse(m1[i]);
			mat_ptr[i] = f_mat44_Invert(m1[i]);
		}
		break;
	}
	case 2: {
		for (uint32 i = 0; i < num; ++i) {
			mat_ptr[i] = m1[i];
			mat44_normalize(mat_ptr[i]);
		}
		break;
	}
	}
	return r;
}





#define DEF_构建矩阵_vs_m_参数 const void* mat1, const Mat44f& mat2
static void* f_JIT_Fun_矩阵变换_vs_m(DEF_构建矩阵_vs_m_参数) {
	vec3* v1 = (*(std::vector<vec3>*)mat1).data();
	uint32 num = (*(std::vector<vec3>*)mat1).size();

	auto r = new std::vector<vec3>(num);
	if (!num) return r;

	vec3* vec_ptr = r->data();

	for (uint32 i = 0; i < num; ++i) {
		vec_ptr[i] = mat2 * (v1[i]) ;
	}

	return r;
}

#define DEF_构建矩阵_v_ms_参数 const vec3& mat1, const void* mat2
static void* f_JIT_Fun_矩阵变换_v_ms(DEF_构建矩阵_v_ms_参数) {
	Mat44f* m2 = (*(std::vector<Mat44f>*)mat2).data();
	uint32 num = (*(std::vector<Mat44f>*)mat2).size();

	auto r = new std::vector<vec3>(num);
	if (!num) return r;

	vec3* vec_ptr = r->data();

	for (uint32 i = 0; i < num; ++i) {
		vec_ptr[i] = (m2[i]) * mat1;
	}
	return r;
}

#define DEF_构建矩阵_vs_ms_参数 const void* mat1, const void* mat2
static void* f_JIT_Fun_矩阵变换_vs_ms(DEF_构建矩阵_ms_ms_参数) {
	vec3* v1 = (*(std::vector<vec3>*)mat1).data();
	Mat44f* m2 = (*(std::vector<Mat44f>*)mat2).data();

	uint32 num = (*(std::vector<vec3>*)mat1).size();
	uint32 num2 = (*(std::vector<Mat44f>*)mat2).size();

	num = DEF_Max(num, num2);

	auto r = new std::vector<vec3>(num);
	if (!num) return r;

	vec3* vec_ptr = r->data();

	bool in1单例 = (*(std::vector<vec3>*)mat1).size() < num;
	bool in2单例 = (*(std::vector<Mat44f>*)mat2).size() < num;

	
	for (uint32 i = 0; i < num; ++i) {
		vec3* inMat_a;
		Mat44f* inMat_b;

		if (in1单例) inMat_a = &v1[0];
		else inMat_a = &v1[i];

		if (in2单例) inMat_b = &m2[0];
		else inMat_b = &m2[i];

		vec_ptr[i] = (*inMat_b) * (*inMat_a);
	}
	
	return r;
}



void f_JIT_Fun_F32s_c_F32s(S_F32Array* r, S_F32Array* a, S_F32Array* b, uint8 方式) {
	uint32 num = DEF_Max(a->count, b->count);

	if(!a->ptr_userData || !b->ptr_userData) return;
	f_单值数组计算(a, b, r, num, 方式);

}

void f_JIT_单值数组计算(S_I32Array* r, S_I32Array* a, S_I32Array* b, uint8 方式) {
	uint32 num = DEF_Max(a->count, b->count);
	f_单值数组计算(a, b, r, num, 方式);

	//bool in1单例 = a->count < num;
	//bool in2单例 = b->count < num;
	//f_core_array_resize((S_Array*)r, num);
	//
	//float32 p0;
	//float32 p1;
	//
	//for (int32 i = 0; i < num; ++i) {
	//
	//	if (in1单例) p0 = a->ptr_userData[0];
	//	else p0 = a->ptr_userData[i];
	//
	//	if (in2单例) p1 = b->ptr_userData[0];
	//	else p1 = b->ptr_userData[i];
	//
	//	switch (方式) {
	//		case 0: r->ptr_userData[i] = p0 + p1; break;
	//		case 1: r->ptr_userData[i] = p0 - p1; break;
	//		case 2: r->ptr_userData[i] = p0 * p1; break;
	//		case 3: r->ptr_userData[i] = p0 / DEF_Max(p1,1); break;
	//		
	//		case 4: r->ptr_userData[i] = DEF_Max(p0, p1); break;
	//		case 5: r->ptr_userData[i] = DEF_Min(p0, p1); break;
	//	}
	//}
}

void f_JIT_单值累计计算(S_F32Array* r, S_F32Array* a, uint8 方式) {
	uint32 num = a->count;
	f_core_array_resize((S_Array*)r, num);
	r->ptr_userData[0] = 0;

	if(num <= 1) return;
	
	float32 v = 0;
	for (int32 i = 0; i < num; ++i) {
		switch (方式) {
			case 0:
				r->ptr_userData[i] = v;
				v += a->ptr_userData[i];
				break;								  
													  
			case 1:									  
				r->ptr_userData[i] = v;
				v -= a->ptr_userData[i];
				break;								  
													  
			case 2:									  
				r->ptr_userData[i] = v;
				v *= a->ptr_userData[i];
				break;								  
													  
			case 3:									  
				r->ptr_userData[i] = v;
				v /= a->ptr_userData[i];
				break;
		}
	} 
}

float32 f_JIT_单值合并计算(S_F32Array* a, uint8 方式) {
	uint32 num = a->count;

	if (num <= 0) return 0;

	float32 v = 0;
	for (int32 i = 0; i < num; ++i) {
		switch (方式) {
			case 0:
				v += a->ptr_userData[i];
				break;

			case 1:
				v -= a->ptr_userData[i];
				break;

			case 2:
				v *= a->ptr_userData[i];
				break;

			case 3:
				v /= a->ptr_userData[i];
				break;
		}
	}
	return v;
}





void f_JIT_旋转向量节点(S_Vec3Array* 向量, const S_Vec3Array* 法线, const S_Vec2Array* UV, uint8 方式) {
	uint32 num = DEF_Max(法线->count, UV->count);

	bool in1单例 = 法线->count < num;
	bool in2单例 = UV->count < num;

	f_core_array_resize((S_Array*)向量, num);

	vec3 a{};
	vec3 上一个顶点{};
	vec3 变换后顶点{};
	for (uint32 i = 0; i < num; ++i) {
		vec2* b;

		if (in2单例) b = &UV->ptr_userData[0];
		else b = &UV->ptr_userData[i];
		vec3 TangentSample = f_SphereSampling(*b);


		if (in1单例) a = 法线->ptr_userData[0];
		else{
			switch (方式) {
			case 1: {
				a = (法线->ptr_userData[i] - 上一个顶点);
				float32 l = vec_normalize(&a);
				a = f_SphereSampling_toWorld(TangentSample, a);
				a *= l;

				变换后顶点 += a;
				向量->ptr_userData[i] = 变换后顶点;
				上一个顶点 = 法线->ptr_userData[i];
				break;
			}
			case 2: {
				a = (法线->ptr_userData[i] - 上一个顶点);
				float32 l = vec_normalize(&a);
				a = f_SphereSampling_toWorld(TangentSample, a);
				a *= l;

				上一个顶点 += a;
				向量->ptr_userData[i] = 上一个顶点;
				break;
			}
			case 3: {
				if (i) {
					a = 法线->ptr_userData[i] - a;
				}
				else {
					a = 法线->ptr_userData[i];
				}
				a = f_SphereSampling_toWorld(TangentSample, a);
				a += 法线->ptr_userData[i];
				向量->ptr_userData[i] = a;
				break;
			}
			default:
				a = 法线->ptr_userData[i];
				向量->ptr_userData[i] = f_SphereSampling_toWorld(TangentSample, a);
				break;
			}
		}
	}
}

void f_JIT_曲线采样(S_F32Array* 值, const S_曲线& curve, const S_F32Array* 步进, const vec2& 钳制) {
	uint32 num = 步进->count;
	f_core_array_resize((S_Array*)值, num);

	for (uint32 i = 0; i < num; ++i) {
		值->ptr_userData[i] = f_graph_钳制曲线采样(步进->ptr_userData[i], curve, 钳制);
	}
}


void f_JIT_步进fm(const S_F32Array* x, const S_F32Array* y, S_F32Array* a, uint8 方式) {
	uint32 num = DEF_Max(x->count, y->count);
	f_core_array_resize((S_Array*)a, num);

	bool x多例 = x->count >= num;
	bool y多例 = y->count >= num;

	for (uint32 i = 0; i < num; ++i) {
		a->ptr_userData[i] = f_JIT_步进f(x多例 ? x->ptr_userData[i] : x->ptr_userData[0], y多例 ? y->ptr_userData[i] : y->ptr_userData[0], 方式);
	}
}
void f_JIT_步进im(const S_I32Array* x, const S_I32Array* y, S_I32Array* a, uint8 方式) {
	uint32 num = DEF_Max(x->count, y->count);
	f_core_array_resize((S_Array*)a, num);

	bool x多例 = x->count >= num;
	bool y多例 = y->count >= num;

	for (uint32 i = 0; i < num; ++i) {
		a->ptr_userData[i] = f_JIT_步进i(x多例 ? x->ptr_userData[i] : x->ptr_userData[0], y多例 ? y->ptr_userData[i] : y->ptr_userData[0], 方式);
	}
}


void f_JIT_坐标变换m(const S_Vec3Array* vert, const S_Vec3Array* loc, const S_Vec3Array* rot, const S_Vec3Array* scal, S_Vec3Array* t) {
	uint32 num = t->count;
	if(!num) return;

	num = DEF_Max(num, loc->count);
	num = DEF_Max(num, rot->count);
	num = DEF_Max(num, scal->count);
	num = DEF_Max(num, vert->count);

	f_core_array_resize((S_Array*)t, num);

	bool 独立1 = loc->count >= num;
	bool 独立2 = rot->count >= num;
	bool 独立3 = scal->count >= num;
	bool 独立4 = vert->count >= num;

//#pragma omp parallel for
	for (int32 i = 0; i < num; ++i) {
		vec3 l;
		if(独立1) l = loc->ptr_userData[i];
		else l = loc->ptr_userData[0];

		vec3 r;
		if(独立2) r = rot->ptr_userData[i];
		else r = rot->ptr_userData[0];

		vec3 s;
		if(独立3) s = scal->ptr_userData[i];
		else s = scal->ptr_userData[0];

		vec3 v;
		if(独立4) v = vert->ptr_userData[i];
		else v = vert->ptr_userData[0];


		t->ptr_userData[i] = f_JIT_坐标变换(v, l, r, s);
	}
}

void f_JIT_位运算Um(const S_UI32Array* x, const S_UI32Array* y, S_UI32Array* a, uint8 方式) {
	uint32 num = DEF_Max(x->count, y->count);
	f_core_array_resize((S_Array*)a, num);

	bool x多例 = x->count >= num;
	bool y多例 = y->count >= num;


#pragma omp parallel for
	for (int32 i = 0; i < num; ++i) {
		a->ptr_userData[i] = f_JIT_位运算U(x多例 ? x->ptr_userData[i] : x->ptr_userData[0], y多例 ? y->ptr_userData[i] : y->ptr_userData[0], 方式);
	}
}

void f_JIT_体素统计_轴向个数(const S_I8Array* 体素, const vec3 比对坐标, int32 轴向, S_I32Array* 个数) {
	ivec3 dim = f_core_array_getDim((S_Array*)体素);

	switch (轴向) {
		case 0: {
			f_core_array_resize((S_Array*)个数, dim.z * dim.y);
			for (int32 z = 0; z < dim.z; ++z) {
				for (int32 y = 0; y < dim.y; ++y) {
					uint32 index = dim.z *z + y;

					uint32 X轴向个数  = 0;
					for (int32 x = 0; x < dim.x; ++x) {
						uint32 index = f_JIT_坐标转索引({x, y, z}, dim, 0);
						X轴向个数 += 体素->ptr_userData[index];
					}
					个数->ptr_userData[index] = X轴向个数;
				}
			}
			
			break;
		}
		case 1: {
			break;
		}
		case 2: {
			break;
		}
		case 3: {
			break;
		}
		case 4: {
			break;
		}
		case 5: {
			break;
		}
	}
}

void f_JIT_体素统计_轴向空洞(const S_I8Array* 体素, int8 值, int32 轴向, S_I32Array* 个数) {
	ivec3 dim = f_core_array_getDim((S_Array*)体素);

	switch (轴向) {
		case 0: {
			f_core_array_resize((S_Array*)个数, dim.z * dim.y);
			for (int32 z = 0; z < dim.z; ++z) {
				for (int32 y = 0; y < dim.y; ++y) {
					uint32 index = dim.z * z + y;

					uint32 X轴向个数 = 0;
					for (int32 x = 0; x < dim.x; ++x) {
						uint32 index = f_JIT_坐标转索引({ x, y, z }, dim, 0);
						int8 v = 体素->ptr_userData[index];
						if (v) {
							break;
						}
						else {
							++X轴向个数;
						}
					}
					个数->ptr_userData[index] = X轴向个数;
				}
			}
			f_core_array_setDim((S_Array*)个数, { 0, dim.y, dim.z });
			break;
		}
		case 1: {
			f_core_array_resize((S_Array*)个数, dim.x * dim.z);
			for (int32 z = 0; z < dim.z; ++z) {
				for (int32 x = 0; x < dim.x; ++x) {
					uint32 index = dim.z * z + x;

					uint32 Y轴向个数 = 0;
					for (int32 y = 0; y < dim.y; ++y) {
						uint32 index = f_JIT_坐标转索引({ x, y, z }, dim, 1);
						int8 v = 体素->ptr_userData[index];
						if (v) {
							break;
						}
						else {
							++Y轴向个数;
						}
					}
					个数->ptr_userData[index] = Y轴向个数;
				}
			}
			f_core_array_setDim((S_Array*)个数, { dim.x, 0, dim.z });
			break;
		}
		case 2: {
			f_core_array_resize((S_Array*)个数, dim.x * dim.y);
			for (int32 y = 0; y < dim.y; ++y) {
				for (int32 x = 0; x < dim.x; ++x) {
					uint32 index = dim.y * y + x;

					uint32 Z轴向个数 = 0;
					for (int32 z = 0; z < dim.z; ++z) {
						uint32 index = f_JIT_坐标转索引({ x, y, z }, dim, 2);
						int8 v = 体素->ptr_userData[index];
						if (v) {
							break;
						}
						else {
							++Z轴向个数;
						}
					}
					个数->ptr_userData[index] = Z轴向个数;
				}
			}
			f_core_array_setDim((S_Array*)个数, { dim.x, dim.y, 0 });
			break;
		}
	}
}

void f_JIT_体素统计_索引坐标(const S_Vec3Array* 体素, S_I32Array* 个数) {
	uint32 num = 体素->count;
	ivec3 dim;

	vec3* v1 = 体素->ptr_userData;
	S_UI32Array* v1Index = f_core_array_Index((S_Array*)体素);

	f_omp_set_threadsNum(DEF_Min(16, num));

	f_core_array_resize((S_Array*)个数, num);
	if (v1Index) {
		
	}
	else {

	}

}

void f_JIT_空间邻近_体素遮罩(const S_Vec3Array* 坐标, const S_Vec3Array* 体素, float32 容差, S_I8Array* 遮罩) {
	ivec3 dim = f_core_array_getDim((S_Array*)体素);
	uint32 num = f_core_array_get_Count((S_Array*)坐标);

	uint32 vNum = dim.x * dim.y * dim.z;
	f_core_array_resize((S_Array*)遮罩, vNum);
	f_core_array_setDim((S_Array*)遮罩, dim);


	vec3* a = 坐标->ptr_userData;
	vec3* b = 体素->ptr_userData;


#pragma omp parallel for num_threads(DEF_Min(2, vNum+1))
	for (int32 i = 0; i < vNum; ++i) {
		float32 最小距离 = 容差;
		uint32 最接近ID = 0xffffffff;

		vec3 bv = b[i];
#pragma omp parallel for num_threads(DEF_Min(16, vNum+1))
		for (int32 k = 0; k < num; ++k) {
			float32 d = vec_len(bv - a[k]);

			if (d < 最小距离) {
				最小距离 = d;
				最接近ID = k;
			}
		}

		if (最接近ID != 0xffffffff) {
			遮罩->ptr_userData[i] = 1;
		}
		else {
			遮罩->ptr_userData[i] = 0;
		}
	}

}

void f_JIT_空间邻近_体素索引(const S_Vec3Array* 坐标, const S_Vec3Array* 体素, int8 轴向, S_UI32Array* 索引) {
	ivec3 dim = f_core_array_getDim((S_Array*)体素);
	uint32 num = f_core_array_get_Count((S_Array*)坐标);

	//f_core_array_resize((S_Array*)索引, num);
	uint32 vNum = dim.x * dim.y * dim.z;
	f_core_array_resize((S_Array*)索引, vNum);
	//uint32 切分 = num / 8;
	vec3* b = 体素->ptr_userData;
	vec3* a = 坐标->ptr_userData;


	S_UI32Array* 坐标_index = f_core_array_Index((S_Array*)坐标);
	if (坐标_index->count) {
#pragma omp parallel for num_threads(DEF_Min(2, vNum+1))
		for (int32 i = 0; i < vNum; ++i) {
			float32 最小距离 = FLT_MAX;
			uint32 最接近ID = 0;

			vec3 bv = b[i];
#pragma omp parallel for num_threads(DEF_Min(16, 坐标_index->count+1))
			for (int32 k = 0; k < 坐标_index->count; ++k) {
				float32 d = vec_len(bv - a[坐标_index->ptr_userData[i]]);

				if (d < 最小距离) {
					最小距离 = d;
					最接近ID = k;
				}
			}
			索引->ptr_userData[i] = 最接近ID;
		}
	}
	else {
		
#pragma omp parallel for num_threads(DEF_Min(2, vNum+1))
		for (int32 i = 0; i < vNum; ++i) {
			float32 最小距离 = FLT_MAX;
			uint32 最接近ID = 0;

			vec3 bv = b[i];
#pragma omp parallel for num_threads(DEF_Min(16, num+1))
			for (int32 k = 0; k < num; ++k) {
				float32 d = vec_len(bv - a[k]);

				if (d < 最小距离) {
					最小距离 = d;
					最接近ID = k;
				}
			}
			索引->ptr_userData[i] = 最接近ID;
		}
	}
}

void f_JIT_空间邻近_体素(const S_Vec3Array* 体素, const S_Vec3Array* 比对坐标, float32 容差, int8 轴向, S_I8Array* 索引) {
	ivec3 dim = f_core_array_getDim((S_Array*)体素);

	f_core_array_resize((S_Array*)索引, dim.x * dim.y * dim.z);
	uint32 num = f_core_array_get_Count((S_Array*)比对坐标);
	uint32 切分 = num / 8;

	vec3* a = 体素->ptr_userData;
	vec3* b = 比对坐标->ptr_userData;

	for (int32 z = 0; z < dim.z; ++z) {
		for (int32 y = 0; y < dim.y; ++y) {
			for (int32 x = 0; x < dim.x; ++x) {
				
				uint32 index = f_JIT_坐标转索引({ x, y, z }, dim, 轴向);
				__m256 ax = _mm256_set1_ps(a[index].x);
				__m256 ay = _mm256_set1_ps(a[index].y);
				__m256 az = _mm256_set1_ps(a[index].z);

				__m256 global_min = _mm256_set1_ps(FLT_MAX);
				float32 最小距离 = FLT_MAX;
				uint32 最接近ID = 0;

				float32 距离[8];
				for (uint32 i = 0; i < num; i+=8) {
					
					__m256 bx = _mm256_set_ps(b[i].x, b[i + 1].x, b[i + 2].x, b[i + 3].x, b[i + 4].x, b[i + 5].x, b[i + 6].x, b[i + 7].x);
					__m256 by = _mm256_set_ps(b[i].y, b[i + 1].y, b[i + 2].y, b[i + 3].y, b[i + 4].y, b[i + 5].y, b[i + 6].y, b[i + 7].y);
					__m256 bz = _mm256_set_ps(b[i].z, b[i + 1].z, b[i + 2].z, b[i + 3].z, b[i + 4].z, b[i + 5].z, b[i + 6].z, b[i + 7].z);

					__m256 dx = _mm256_sub_ps(ax, bx);
					__m256 dy = _mm256_sub_ps(ay, by);
					__m256 dz = _mm256_sub_ps(az, bz);

					dx = _mm256_mul_ps(dx, dx);
					dy = _mm256_mul_ps(dy, dy);
					dz = _mm256_mul_ps(dz, dz);

					__m256 dist_sq = _mm256_add_ps(_mm256_add_ps(dx, dy), dz);
					global_min = _mm256_min_ps(global_min, _mm256_sqrt_ps(dist_sq));


					_mm256_storeu_ps(距离, global_min);
					for (uint32 k = 0; k < 8; ++k) {
						if (距离[k] < 最小距离) {
							最小距离 = 距离[k];
							最接近ID = i + k;
						}
					}
				}

				

				for (uint32 k = 切分*8; k < num; ++k) {
					float32 d = vec_len(a[index] - b[k]);
					if (距离[k] < 最小距离) {
						最小距离 = d;
						最接近ID = k;
					}
				}

				
				索引->ptr_userData[index] = 最接近ID;
			}
		}
	}
}



//static float32 f_轴向坐标距离(float32 minD, float32 minV, vec3& 主坐标, vec3 次坐标, int8 轴向) {
//	float32 d;
//	float32 轴向距离;
//	switch (轴向) {
//		case 0: {
//			轴向距离 = 次坐标.x - 主坐标.x;
//			次坐标.x = 主坐标.x;
//			d = length(主坐标 - 次坐标);
//			break;
//		}
//		case 1: {
//			轴向距离 = 次坐标.y - 主坐标.y;
//			次坐标.y = 主坐标.y;
//			d = length(主坐标 - 次坐标);
//			break;
//		}
//		case 2: {
//			轴向距离 = 次坐标.z - 主坐标.z;
//			次坐标.z = 主坐标.z;
//			d = length(主坐标 - 次坐标);
//			break;
//		}
//		default:
//			break;
//	}
//	if (d <= minV) {
//		minV = d;
//
//		轴向距离 = fabs(轴向距离);
//		if (轴向距离 < minD) {
//			minD = 轴向距离;
//		}
//	}
//}
static float32 f_轴向最近距离(vec3& 主坐标, const S_Vec3Array* 比对坐标, int8 轴向) {//, float32 容差
	float32 minD = FLT_MAX;
	float32 minV = FLT_MAX;

	S_UI32Array* index = f_core_array_Index((S_Array*)比对坐标);
	uint32 num;
	if (index) {
		num = index->count;
	}
	else {
		num = 比对坐标->count;
	}

	for (uint32 k = 0; k < num; ++k) {
		vec3 次坐标;
		if (index) {
			次坐标 = 比对坐标->ptr_userData[index->ptr_userData[k]];
		}
		else {
			次坐标 = 比对坐标->ptr_userData[k];
		}

		float32 d;
		float32 轴向距离;
		switch (轴向) {
			case 0: {
				轴向距离 = 次坐标.x - 主坐标.x;
				次坐标.x = 主坐标.x;
				d = length(主坐标 - 次坐标);
				break;
			}
			case 1: {
				轴向距离 = 次坐标.y - 主坐标.y;
				次坐标.y = 主坐标.y;
				d = length(主坐标 - 次坐标);
				break;
			}
			case 2: {
				轴向距离 = 次坐标.z - 主坐标.z;
				次坐标.z = 主坐标.z;
				d = length(主坐标 - 次坐标);
				break;
			}
			default:
				break;
		}

		if (d <= minV) {
			minV = d;

			轴向距离 = fabs(轴向距离);
			if (轴向距离 < minD) {
				minD = 轴向距离;
			}
		}
	}

	return minD;
}
static uint32 f_轴向最近索引(vec3& 主坐标, const S_Vec3Array* 比对坐标, int8 轴向) {
	float32 minD = FLT_MAX;
	float32 minV = FLT_MAX;
	uint32 最近索引 = 0;

	S_UI32Array* index = f_core_array_Index((S_Array*)比对坐标);
	uint32 num;
	if (index) {
		num = index->count;
	}
	else {
		num = 比对坐标->count;
	}

	for (uint32 k = 0; k < num; ++k) {
		vec3 次坐标;
		if (index) {
			次坐标 = 比对坐标->ptr_userData[index->ptr_userData[k]];
		}
		else {
			次坐标 = 比对坐标->ptr_userData[k];
		}

		float32 d;
		float32 轴向距离;
		switch (轴向) {
			case 0: {
				轴向距离 = 次坐标.x - 主坐标.x;
				次坐标.x = 主坐标.x;
				d = length(主坐标 - 次坐标);
				break;
			}
			case 1: {
				轴向距离 = 次坐标.y - 主坐标.y;
				次坐标.y = 主坐标.y;
				d = length(主坐标 - 次坐标);
				break;
			}
			case 2: {
				轴向距离 = 次坐标.z - 主坐标.z;
				次坐标.z = 主坐标.z;
				d = length(主坐标 - 次坐标);
				break;
			}
			default:
				break;
		}

		if (d <= minV) {
			minV = d;

			轴向距离 = fabs(轴向距离);
			if (轴向距离 < minD) {
				minD = 轴向距离;
				最近索引 = k;
			}
		}
	}

	return 最近索引;
}

void f_JIT_空间邻近_轴向最近距离(const S_Vec3Array* vert, const S_Vec3Array* 比对坐标, int8 轴向, bool 反向, S_F32Array* 最近距离) {
	
	S_UI32Array* index = f_core_array_Index((S_Array*)vert);

	if (index) {
		f_core_array_resize((S_Array*)最近距离, index->count);

		for (uint32 i = 0; i < index->count; ++i) {
			vec3 主坐标 = vert->ptr_userData[index->ptr_userData[i]];
			最近距离->ptr_userData[i] = f_轴向最近距离(主坐标, 比对坐标, 轴向);
		}
	}
	else {
		f_core_array_resize((S_Array*)最近距离, vert->count);

		for (uint32 i = 0; i < vert->count; ++i) {
			vec3 主坐标 = vert->ptr_userData[i];
			最近距离->ptr_userData[i] = f_轴向最近距离(主坐标, 比对坐标, 轴向);
		}
	}
}




void f_JIT_空间邻近_轴向最近索引(const S_Vec3Array* vert, const S_Vec3Array* 比对坐标, int8 轴向, bool 反向, S_UI32Array* 最近索引) {
	
	S_UI32Array* index = f_core_array_Index((S_Array*)vert);
	if (index) {
		f_core_array_resize((S_Array*)最近索引, index->count);

		for (uint32 i = 0; i < index->count; ++i) {
			float32 minD = FLT_MAX;
			float32 minV = FLT_MAX;

			vec3 主坐标 = vert->ptr_userData[index->ptr_userData[i]];
			最近索引->ptr_userData[i] = f_轴向最近索引(主坐标, 比对坐标, 轴向);
		}
	}
	else {
		f_core_array_resize((S_Array*)最近索引, vert->count);

		for (uint32 i = 0; i < vert->count; ++i) {
			float32 minD = FLT_MAX;
			float32 minV = FLT_MAX;

			vec3 主坐标 = vert->ptr_userData[i];
			最近索引->ptr_userData[i] = f_轴向最近索引(主坐标, 比对坐标, 轴向);
		}
	}
}






void f_node_所有计算类节点JIT初始化() {
	f_代码构建_添加JIT初始化函数指针(DEF_S(vec3_len), DEF_S(float32), "const vec3& vec", vec3_len);

	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fn_逻辑计算), DEF_S(void), "float32, float32, int8&, uint8", f_JIT_Fn_逻辑计算);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fn_逻辑计算m), DEF_S(void),  "S_F32Array*, S_F32Array*, S_I8Array*, uint8", f_JIT_Fn_逻辑计算m);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fn_单目计算m), DEF_S(void), "S_F32Array*, S_F32Array*, int32", f_JIT_Fn_单目计算m);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fun_F32s_c_F32s), "void", "S_F32Array* r, S_F32Array* a, S_F32Array* b, uint8 方式", f_JIT_Fun_F32s_c_F32s);

	f_代码构建_添加JIT初始化函数指针(DEF_S(f_graph_计算圆坐标v3_JIT), "void", "const vec3 中心, const float32 半径, uint32 细分, S_Vec3Array* 结果", f_graph_计算圆坐标v3_JIT);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_graph_计算直线坐标), "void", "vec3 方向, float32 长度, uint32 细分, void* data", f_graph_计算直线坐标);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_graph_构建范围体素坐标), "void", "vec3 大小, uvec3 细分, S_Vec3Array* data, bool, bool", f_graph_构建范围体素坐标);
	f_代码构建_添加JIT初始化函数指针(DEF_S(vec_add_3_1), "vec3", "const vec3& vec, const float32& 加数向量", vec_add_3_1);
	f_代码构建_添加JIT初始化函数指针(DEF_S(vec_add_3_3), "vec3", "const vec3& vec, vec3& 加数向量", vec_add_3_3);
	f_代码构建_添加JIT初始化函数指针(DEF_S(vec_multi_3_3), "vec3", "const vec3& vec, vec3& 加数向量", vec_multi_3_3);

	

	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fun_vec3_c_f32), "vec3", DEF_S(DEF_V3_F_参数), f_JIT_Fun_vec3_c_f32);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fun_vec3_c_vec3), "vec3", DEF_S(DEF_V3_V3_参数), f_JIT_Fun_vec3_c_vec3);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fun_vec3s_c_f), "void", DEF_S(DEF_V3S_F_参数), f_JIT_Fun_vec3s_c_f);

	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fun_vec3s_c_fs), "void", DEF_S(DEF_V3S_Fs_参数), f_JIT_Fun_vec3s_c_fs);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fun_vec3s_c_vec3s), DEF_S(S_Vec3Array*), "const S_Vec3Array* , const S_Vec3Array* , S_Vec3Array* , int32 ", f_JIT_Fun_vec3s_c_vec3s);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_单值数组计算), DEF_S(void), "S_I32Array*, S_I32Array*, S_I32Array*, uint8", f_JIT_单值数组计算);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_单值累计计算), DEF_S(void), "S_F32Array*, S_F32Array*, uint8", f_JIT_单值累计计算);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_单值合并计算), DEF_S(float32), "S_F32Array*, uint8", f_JIT_单值合并计算);

	f_代码构建_添加JIT初始化函数指针(DEF_S(f_mat44_构建移动矩阵), "Mat44f", "const vec3& s", f_mat44_构建移动矩阵);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_mat44_构建缩放矩阵), "Mat44f", "const vec3& s", f_mat44_构建缩放矩阵);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_mat44_构建行式旋转矩阵), "Mat44f", "const vec3& a, float32 angle", f_mat44_构建行式旋转矩阵);

	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fun_矩阵计算_mm), "Mat44f", DEF_S(DEF_构建矩阵_m_m_参数), f_JIT_Fun_矩阵计算_mms);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fun_矩阵计算_mms), "void*", DEF_S(DEF_构建矩阵_m_ms_参数), f_JIT_Fun_矩阵计算_mms);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fun_矩阵计算_msm), "void*", DEF_S(DEF_构建矩阵_ms_m_参数), f_JIT_Fun_矩阵计算_msm);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fun_矩阵计算_msms), "void*", DEF_S(DEF_构建矩阵_ms_ms_参数), f_JIT_Fun_矩阵计算_msms);

	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fun_矩阵变换_vs_m), "void*", DEF_S(DEF_构建矩阵_vs_m_参数), f_JIT_Fun_矩阵变换_vs_m);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fun_矩阵变换_v_ms), "void*", DEF_S(DEF_构建矩阵_v_ms_参数), f_JIT_Fun_矩阵变换_v_ms);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fun_矩阵变换_vs_ms), "void*", DEF_S(DEF_构建矩阵_vs_ms_参数), f_JIT_Fun_矩阵变换_vs_ms);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_坐标变换), DEF_S(vec3), "const vec3&, const vec3&, const vec3&, const vec3&", f_JIT_坐标变换);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_坐标变换m), DEF_S(void), "const S_Vec3Array*, const S_Vec3Array*, const S_Vec3Array*, const S_Vec3Array*, S_Vec3Array*", f_JIT_坐标变换m);
	

	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fn_三角函数s), "void", "S_F32Array* inData, S_F32Array* outData, uint8 type", f_JIT_Fn_三角函数s);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fn_三角函数), "float32", "float32 inData, uint8 type", f_JIT_Fn_三角函数);

	f_代码构建_添加JIT初始化函数指针(DEF_S(f_surface_线段方向), "void", "const S_Vec3Array * inData, S_Vec3Array * outData", f_surface_线段方向);

	//f_代码构建_添加JIT初始化函数指针(DEF_S(vec_len), "float32", "const vec3& vec", vec_len);
	f_代码构建_添加JIT初始化函数指针(DEF_S(vec_3转4), "vec4", "const vec3& vec, const float32 填充数", vec_3转4);
	f_代码构建_添加JIT初始化函数指针(DEF_S(vec_4转3), "vec3", "const vec4& vec", vec_4转3);
	f_代码构建_添加JIT初始化函数指针(DEF_S(vec_f3转u2), "uvec2", "const vec3& vec", vec_f3转u2);

	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_向量长度m), DEF_S(void), "S_F32Array*, const S_Vec3Array*, uint8", f_math_向量长度m);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_向量归一化), "vec3", "const vec3& dirA, uint8 type", f_math_向量归一化);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_向量归一化m), "void", "const S_Vec3Array* dirA, S_Vec3Array* r, uint8 type", f_math_向量归一化m);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_两向量标量), "float32", "const vec3& dirA, const vec3& dirB, uint8 type", f_math_两向量标量);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_两向量标量m), "void", "const S_Vec3Array* dirA, const S_Vec3Array* dirB, S_F32Array* r, uint8 type", f_math_两向量标量m);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_两向量叉积), "vec3", "const vec3& dirA, const vec3& dirB", f_math_两向量叉积);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_两向量叉积m), "void", "const S_Vec3Array* dirA, const S_Vec3Array* dirB, S_Vec3Array* r", f_math_两向量叉积m);

	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fn_混合m), DEF_S(void), "const S_F32Array*, const S_F32Array*, const S_F32Array*, S_F32Array*", f_JIT_Fn_混合m);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fn_矢量混合m), DEF_S(void), "const S_Vec3Array*, const S_Vec3Array*, const S_F32Array*, S_Vec3Array*", f_JIT_Fn_矢量混合m);

	f_代码构建_添加JIT初始化函数指针(DEF_S(f_graph_quat相乘), "vec4", "const vec4& q1, const vec4& q2", f_graph_quat相乘);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_graph_quat两向量), "vec4", "const vec3& v, const vec3& q2", f_graph_quat两向量);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_graph_quat变换坐标), "vec3", "const vec4& v, const vec3& q2", f_graph_quat变换坐标);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_graph_钳制曲线采样), "float32", "float32  采样位置, const S_曲线& curve, const vec2 钳制", f_graph_钳制曲线采样);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_graph_旋转角转四元数), DEF_S(vec4), "const vec3& 归一化向量, float 弧度", f_graph_旋转角转四元数);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_graph_quatTranform), DEF_S(vec3), "const vec4& q, const vec3& pos", f_graph_quatTranform);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_graph_quatTranformInv), DEF_S(vec3), "const vec4& q, const vec3& pos", f_graph_quatTranformInv);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_graph_从轴向角度计算四元数), DEF_S(vec4), "const vec3&, float", f_graph_从轴向角度计算四元数);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_quat相乘m), "void", "const S_Vec4Array* dirA, const S_Vec4Array* dirB, S_Vec4Array* r", f_math_quat相乘m);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_quat以轴向和角度构建m), "void", "S_Vec4Array* quat, const S_Vec3Array* v, const S_F32Array* a", f_math_quat以轴向和角度构建m);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_绕点旋转), DEF_S(vec3), "const vec3&, const vec3&, const float32, const vec3&", f_math_绕点旋转);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_绕点旋转m), DEF_S(void), "S_Vec3Array*, const S_Vec3Array*, const S_Vec3Array*, const S_F32Array*, const vec3&", f_math_绕点旋转m);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_轴向旋转变换), DEF_S(vec3), "vec3, vec3, float32, int32", f_math_轴向旋转变换);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_轴向旋转变换m), DEF_S(void), "S_Vec3Array*, const S_Vec3Array*, const S_Vec3Array*, S_F32Array*, int32", f_math_轴向旋转变换m);



	f_代码构建_添加JIT初始化函数指针(DEF_S(f_graph_四元数转欧拉角), DEF_S(vec3), "const vec4& quat", f_graph_四元数转欧拉角);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_mat3x3_quat), DEF_S(mat3X3), "const vec4& quat", f_mat3x3_quat);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_mat4x4_quat), DEF_S(Mat44f), "const vec4& quat", f_mat4x4_quat);

	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_quat变换m), "void", "const S_Vec3Array* dirA, const S_Vec4Array* dirB, S_Vec3Array* r, int32", f_math_quat变换m);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_四元数转欧拉角m), "void", "const S_Vec4Array* quat, S_Vec3Array* r", f_math_四元数转欧拉角m);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_四元数转3X3矩阵m), "void", "const S_Vec4Array* quat, S_Mat33Array* r", f_math_四元数转3X3矩阵m);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_四元数转4X4矩阵m), "void", "const S_Vec4Array* quat, S_Mat44Array* r", f_math_四元数转4X4矩阵m);

	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_mat44_变换m), "void", "const S_Vec3Array* dirA, const S_Mat44Array* dirB, S_Vec3Array* r", f_math_mat44_变换m);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_mat44_相乘), "Mat44f", "const Mat44f& dirA, const Mat44f& dirB", f_math_mat44_相乘);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_math_mat44_相乘m), "void", "const S_Mat44Array* dirA, const S_Mat44Array* dirB, S_Mat44Array* r", f_math_mat44_相乘m);

	f_代码构建_添加JIT初始化函数指针(DEF_S(f_mat_平面构建), "void", "const S_Vec3Array*, S_Vec4Array*", f_mat_平面构建);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_graph_顶点构建平面), "vec4", "const vec3 point[3]", f_graph_顶点构建平面);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_mat_点到平面距离), "void", "const S_Vec3Array*, const S_Vec4Array*, S_F32Array*", f_mat_点到平面距离);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_graph_点到平面距离), "float32", "const vec3&, const vec4&", f_graph_点到平面距离);
	//f_代码构建_添加JIT初始化函数指针(DEF_S(f_graph_线段平面相交), "bool", "const vec3&, const vec3&, const vec4&, vec3&", f_graph_线段平面相交);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_mat_射线平面相交), DEF_S(void), "const S_Vec3Array*, const S_Vec4Array*, S_Vec3Array*", f_mat_射线平面相交);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_mat_点统计v3), DEF_S(vec3), "const S_Vec3Array* point, const S_Props* 计算方式", f_mat_点统计v3);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_mat_点统计v2), DEF_S(vec2), "const S_Vec2Array* point, const S_Props* 计算方式", f_mat_点统计v2);


	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_旋转向量节点), DEF_S(void), "S_Vec3Array * 向量, const S_Vec3Array * 法线, const S_Vec2Array * UV, uint8 方式", f_JIT_旋转向量节点);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_SphereSampling), DEF_S(vec3), "vec2 uv", f_SphereSampling);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_SphereSampling_toWorld), DEF_S(vec3), "vec3 ss, vec3 N", f_SphereSampling_toWorld);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_曲线采样), DEF_S(void), "S_F32Array* 值, const S_曲线& curve, const S_F32Array* 步进, const vec2& 钳制", f_JIT_曲线采样);
	

	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fn_设置矢量分量), DEF_S(vec3), "const vec3& 矢量, float32 分量, int8 分量ID", f_JIT_Fn_设置矢量分量);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_Fn_设置矢量分量m), DEF_S(void), "const S_Vec3Array*, const S_F32Array*, int8, S_Vec3Array*", f_JIT_Fn_设置矢量分量m);

	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_步进f), DEF_S(float32), "float32& x, float32& edge, uint8 方式", f_JIT_步进f);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_步进i), DEF_S(int32), "int32& x, int32& edge, uint8 方式", f_JIT_步进i);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_步进fm), DEF_S(void), "const S_F32Array* x, const S_F32Array* y, S_F32Array* a, uint8 方式", f_JIT_步进fm);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_步进im), DEF_S(void), "const S_I32Array* x, const S_I32Array* y, S_I32Array* a, uint8 方式", f_JIT_步进im);
	
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_位运算U), DEF_S(uint32), "uint32 a, uint32 b, uint8 方式", f_JIT_位运算U);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_位运算Uxx), DEF_S(void), "uint32& a, const uint32& b, uint8 方式", f_JIT_位运算Uxx);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_位运算Um), DEF_S(void), "const S_UI32Array* x, const S_UI32Array* y, S_UI32Array* a, uint8 方式", f_JIT_位运算Um);
	//f_代码构建_添加JIT初始化函数指针(DEF_S(length), "float32", "float32 x", length);


	f_代码构建_添加JIT初始化函数指针(DEF_S(f_bvh_包围坐标检测), DEF_S(bool), "const S_CubeArray* , const S_Vec3Array* , S_Vec3Array* , int32 ", f_bvh_包围坐标检测);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_bvh_包围索引检测), DEF_S(bool), "const S_CubeArray* , const S_Vec3Array* , S_UI32Array* , int32 ", f_bvh_包围索引检测);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_bvh_包围索引坐标), DEF_S(bool), "const S_CubeArray* , const S_Vec3Array* , S_iVec3Array* ", f_bvh_包围索引坐标);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_bvh_包围盒自检测), DEF_S(bool), "const S_CubeArray* 包围盒, const S_Cube& 坐标, int32 算法", f_bvh_包围盒自检测);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_vec_取矢量分量), DEF_S(void), "const S_Vec3Array* , const S_I8Array* , S_F32Array* , const S_Props& ", f_vec_取矢量分量);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_体素统计_轴向空洞), DEF_S(void), "const S_I8Array* , const int8 , int32 , S_I32Array* ", f_JIT_体素统计_轴向空洞);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_空间邻近_体素遮罩), DEF_S(void), "const S_Vec3Array* , const S_Vec3Array* , float32 , S_I8Array* ", f_JIT_空间邻近_体素遮罩);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_空间邻近_轴向最近距离), DEF_S(void), "const S_Vec3Array* , const S_Vec3Array* , int8 , bool , S_F32Array* ", f_JIT_空间邻近_轴向最近距离);
	f_代码构建_添加JIT初始化函数指针(DEF_S(f_JIT_空间邻近_轴向最近索引), DEF_S(void), "const S_Vec3Array* , const S_Vec3Array* , int8 , bool , S_UI32Array* ", f_JIT_空间邻近_轴向最近索引);


}













//__m256 ax = _mm256_set1_ps(a[index].x);
//__m256 ay = _mm256_set1_ps(a[index].y);
//__m256 az = _mm256_set1_ps(a[index].z);
//
//__m256 global_min = _mm256_set1_ps(FLT_MAX);
//
//
//float32 距离[8];
//
//for (int32 i = 0; i < num; i += 8) {
//
//	__m256 bx = _mm256_set_ps(b[i].x, b[i + 1].x, b[i + 2].x, b[i + 3].x, b[i + 4].x, b[i + 5].x, b[i + 6].x, b[i + 7].x);
//	__m256 by = _mm256_set_ps(b[i].y, b[i + 1].y, b[i + 2].y, b[i + 3].y, b[i + 4].y, b[i + 5].y, b[i + 6].y, b[i + 7].y);
//	__m256 bz = _mm256_set_ps(b[i].z, b[i + 1].z, b[i + 2].z, b[i + 3].z, b[i + 4].z, b[i + 5].z, b[i + 6].z, b[i + 7].z);
//
//	__m256 dx = _mm256_sub_ps(ax, bx);
//	__m256 dy = _mm256_sub_ps(ay, by);
//	__m256 dz = _mm256_sub_ps(az, bz);
//
//	dx = _mm256_mul_ps(dx, dx);
//	dy = _mm256_mul_ps(dy, dy);
//	dz = _mm256_mul_ps(dz, dz);
//
//	__m256 dist_sq = _mm256_add_ps(_mm256_add_ps(dx, dy), dz);
//	global_min = _mm256_min_ps(global_min, _mm256_sqrt_ps(dist_sq));
//
//
//	_mm256_storeu_ps(距离, global_min);
//	for (uint32 k = 0; k < 8; ++k) {
//		if (距离[k] < 最小距离) {
//			最小距离 = 距离[k];
//			最接近ID = i + k;
//		}
//	}
//}
//
//
//
//for (uint32 k = 切分 * 8; k < num; ++k) {
//	float32 d = vec_len(a[index] - b[k]);
//	if (d < 最小距离) {
//		最小距离 = d;
//		最接近ID = k;
//	}
//}


